/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.football.lottery.util;

import java.io.File;
import javax.swing.filechooser.FileFilter;

/**
 *
 * @author I am god
 */
public class MyFileFilter extends FileFilter
{
    private String ext;

    public MyFileFilter(String ext)
    {
        this.ext = ext;
    }

    @Override
    public boolean accept(File file)
    {
        if (file.isDirectory())
        {
            return true;
        }

        String fileName = file.getName();
        int index = fileName.lastIndexOf('.');

        if (index > 0 && index < fileName.length() - 1)
        {
            String extension = fileName.substring(index + 1).toLowerCase();
            if (extension.equals(ext))
            {
                return true;
            }
        }
        return false;
    }

  @Override
    public String getDescription()
    {
        if (ext.equals("xls"))
        {
            return "Microsoft Excel(*.xls)";
        }
        if (ext.equals("xml"))
        {
            return "XML FILE(*.xml)";
        }
        return "";
    }
}
